//菜单
function create(root,params) {
    //加载
    $(root).load("assembly/nav.html",function () {
        //设置定位
        setPos(params.pos);
        setContext(params.selectColor,params.data);


        $('#nav_container').on('click','.nav_bt',function () {
            let index = $(this).attr("key");
            let record = params.data[index];
            let onClick = params.onClick;
            onClick(index,record);

        })
    });
}

//设置定位
function setPos(pos) {
    if(pos == ""){
        pos = 'bottom';
    }

    if(pos == 'bottom'){
        console.log("nav_container")
        $("#nav_container").addClass("nav_pos_bottom");
    }
}

//设置内容
function setContext(selectColor,data) {
    let doc = "";
    if(data != null && data.length > 0){
        let width = 100/data.length + "%";
        console.log("nav 宽度为："+width)
        for (let i = 0 ; i < data.length ; i++){
            //读取hash
            let path = "#/"+data[i].hash;
            if(location.hash == path){
                doc = doc + '<div style="width: '+width+';height: 100%;float: left" key="'+i+'" class="nav_bt">' +
                    '<div class="nav_container_p_img"><img src="'+data[i].selectIcon+'" style="width: 100%;height: 100%"/></div>' +
                    '<div class="nav_container_p_title" style="color: '+selectColor+'">'+data[i].title+'</div>' +
                    '</div>';
            }else {
                doc = doc + '<div style="width: '+width+';height: 100%;float: left;cursor: pointer" left" key="'+i+'" class="nav_bt">' +
                    '<div class="nav_container_p_img"><img src="'+data[i].icon+'" style="width: 100%;height: 100%"/></div>' +
                    '<div class="nav_container_p_title">'+data[i].title+'</div>' +
                    '</div>';
            }

        }
    }
    $("#nav_container").append(doc);
}

$(document).ready(function () {


});



